#include "MazeTypes.h"
#include "DX11ErrorReport.h"

Cell::Cell()
{
	m_cellWalls[NORTH] = false;
	m_cellWalls[EAST] = false;
	m_cellWalls[SOUTH] = false;
	m_cellWalls[WEST] = false;

	m_size = -1.0f;
	m_posType = NO_TYPE;
	m_roomWalls = CellWall(NORTH | EAST | SOUTH | WEST);
	m_cellType = EMPTY;

	//m_oobb.axis[0] = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
	//m_oobb.axis[1] = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	//m_oobb.axis[2] = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
}

void Cell::Draw()
{

}

//void Cell::SetCellWall(CellWall wall, bool isOpen)
//{
//	m_cellWalls[wall] = isOpen;
//}

PositionType Cell::GetPosType() const
{
	return m_posType;
}

void Cell::SetPosType(PositionType ptype)
{
	m_posType = ptype;

	// set available doors
	if (ptype == CENTRE)
	{
		// all four doors are open
		m_availableDoors.first = m_posType;
		m_availableDoors.second = CellWall(NORTH | EAST | SOUTH | WEST);
	}
	else 
	{
		if (m_posType == PositionType(TOP | LEFT))
		{
			m_availableDoors.second = CellWall(EAST | SOUTH);
		}
		else if (m_posType == PositionType(TOP | RIGHT))
		{
			m_availableDoors.second = CellWall(SOUTH | WEST);
		}
		else if (m_posType == PositionType(BOT | LEFT))
		{
			m_availableDoors.second = CellWall(EAST | NORTH);
		}
		else if (m_posType == PositionType(BOT | RIGHT))
		{
			m_availableDoors.second = CellWall(WEST | NORTH);
		}
		else if (m_posType == TOP)
		{
			m_availableDoors.second = CellWall(SOUTH | EAST | WEST);
		}
		else if (m_posType == BOT)
		{
			m_availableDoors.second = CellWall(NORTH | EAST | WEST);
		}
		else if (m_posType == LEFT)
		{
			m_availableDoors.second = CellWall(NORTH | EAST | SOUTH);
		}
		else if (m_posType == RIGHT)
		{
			m_availableDoors.second = CellWall(NORTH | SOUTH | WEST);
		}
		m_availableDoors.first = m_posType;
	}
	m_nonOpenedWalls = m_availableDoors.second;
	//m_roomWalls = m_availableDoors.second;
}

CellWall Cell::GetCellWalls() const
{
	return m_availableDoors.second;
}

CellWall Cell::GetAvailableWalls() const
{
	return m_nonOpenedWalls;
	//return m_availableDoors.second;
}

void Cell::RemoveAvailableWall(CellWall wall)
{
	// check that the wall is there
	if (m_nonOpenedWalls > (m_nonOpenedWalls ^ wall))
	{
		// remove it
		m_nonOpenedWalls = CellWall(m_nonOpenedWalls ^ wall);
		return;
	}
	DX11ErrorMsg(L"no such wall", L"MazeTypes: removeAvailableWalls", MB_OK);
}

void Cell::RemoveRoomWall(CellWall wall)
{
	if (m_roomWalls > (m_roomWalls ^ wall))
	{
		// remove it
		m_roomWalls = CellWall(m_roomWalls ^ wall);
		return;
	}
	//DX11ErrorMsg(L"no such wall", L"MazeTypes: removeAvailableWalls", MB_OK);
}

CellWall Cell::GetRoomWalls() const
{
	return m_roomWalls;
}

void Cell::SetSouthWallPosition(const D3DXVECTOR3& pos)
{
	m_positionSouth = pos;
}

D3DXVECTOR3 Cell::GetSouthWallPosition() const
{
	return m_positionSouth;
}

void Cell::SetWestWallPosition(const D3DXVECTOR3& pos)
{
	m_positionWest = pos;
}

D3DXVECTOR3 Cell::GetWestWallPosition() const
{
	return m_positionWest;
}

void Cell::SetNorthWallPosition(const D3DXVECTOR3& pos)
{
	m_positionNorth = pos;
}

D3DXVECTOR3 Cell::GetNorthWallPosition() const
{
	return m_positionNorth;
}

void Cell::SetEastWallPosition(const D3DXVECTOR3& pos)
{
	m_positionEast = pos;
}

D3DXVECTOR3 Cell::GetEastWallPosition() const
{
	return m_positionEast;
}

void Cell::SetCellType(CellType type)
{
	m_cellType = type;
}

CellType Cell::GetCellType() const
{
	return m_cellType;
}

OOBB3& Cell::GetOOBB()
{
	return m_oobb;
}